/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package isd.facturacion.dao;

import isd.facturacion.modelo.FC_Circuito;
import isd.facturacion.modelo.FC_CircuitoPK;
import isd.facturacion.modelo.FC_CodigoCircuito;
import isd.facturacion.modelo.FC_Comprobante;
import isd.general.dao.BaseDAO;
import isd.inventario.modelo.ST_Comprobante;
import isd.ventas.modelo.VT_Comprobante;
import isd.tesoreria.modelo.CJ_Comprobante;
import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author Claudio
 */
@Stateless
public class FC_CircuitoDAO extends BaseDAO {
    
    public FC_Circuito getCircuito(FC_CircuitoPK idPK){
        return em.find(FC_Circuito.class, idPK);
    }

    public FC_Comprobante getComprobanteFacturacion(String circom, String cirapl, String modcom, String codcom) {

        try{

            String sQuery = "SELECT i.comprobante FROM FC_ItemCircuitoFacturacion i "
                    + "WHERE i.idPK.cirapl = '"+cirapl+"' "
                    + "AND i.idPK.circom = '"+circom+"' "
                    + "AND i.idPK.modulo = '"+modcom+"' "
                    + "AND i.idPK.codcom = '"+codcom+"' ";
            return queryObject(FC_Comprobante.class, sQuery);

        }catch(Exception e){
            return null;
        }
       
    }

    public VT_Comprobante getComprobanteVenta(String circom, String cirapl, String modcom, String codcom) {

        try{

            String sQuery = "SELECT i.comprobante FROM FC_ItemCircuitoVenta i "
                    + "WHERE i.idPK.cirapl = '"+cirapl+"' "
                    + "AND i.idPK.circom = '"+circom+"' "
                    + "AND i.idPK.modulo = '"+modcom+"' "
                    + "AND i.idPK.codcom = '"+codcom+"' ";
            return queryObject(VT_Comprobante.class, sQuery);

        }catch(Exception e){
            return null;
        }
    }

    public CJ_Comprobante getComprobanteTesoreria(String circom, String cirapl, String modcom, String codcom) {

        try{

            String sQuery = "SELECT i.comprobante FROM FC_ItemCircuitoTesoreria i "
                    + "WHERE i.idPK.cirapl = '"+cirapl+"' "
                    + "AND i.idPK.circom = '"+circom+"' "
                    + "AND i.idPK.modulo = '"+modcom+"' "
                    + "AND i.idPK.codcom = '"+codcom+"' ";
            return queryObject(CJ_Comprobante.class, sQuery);

        }catch(Exception e){
            return null;
        }
    }

    public ST_Comprobante getComprobanteStock(String circom, String cirapl, String modcom, String codcom) {
        try{

            String sQuery = "SELECT i.comprobante FROM FC_ItemCircuitoStock i "
                    + "WHERE i.idPK.cirapl = '"+cirapl+"' "
                    + "AND i.idPK.circom = '"+circom+"' "
                    + "AND i.idPK.modulo = '"+modcom+"' "
                    + "AND i.idPK.codcom = '"+codcom+"' ";
            return queryObject(ST_Comprobante.class, sQuery);

        }catch(Exception e){
            return null;
        }
    }

    public FC_CodigoCircuito getCodigoCircuito(String codigo) {

        return em.find(FC_CodigoCircuito.class, codigo);

    }

    public List<FC_CodigoCircuito> getListaCodigoCircuito() {

        return getLista(FC_CodigoCircuito.class, true, -1, -1);
    }

}
